package com.jic.member.impl;

import java.lang.Long;
import java.util.List;

import com.jic.common.base.vo.RestResult;
import com.jic.member.entity.MememberGrowthAction;
import com.jic.member.mapper.MememberGrowthActionMapper;
import com.jic.member.response.MemberGrowthRuleResponse;
import com.jic.member.service.MememberGrowthActionService;
import com.jic.common.base.vo.PageResult;
import com.jic.common.base.vo.Page;
import com.jic.member.service.MememberGrowthRuleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 会员等级管理-评价-分享-点赞-晒单-收藏赠送表
 *
 * @author :
 * @version : v1.0.0
 * @email :
 * @since : 2020-04-10 11:00:00
 */
@Service
public class MememberGrowthActionServiceImpl implements MememberGrowthActionService {

    @Resource
    private MememberGrowthActionMapper mememberGrowthActionMapper;
    @Autowired
    MememberGrowthRuleService mememberGrowthRuleService;

    @Override
    public long insert(MememberGrowthAction mememberGrowthAction) {
        long flag = mememberGrowthActionMapper.insert(mememberGrowthAction);
        return flag;
    }

    @Override
    public long delete(Long id) {
        return mememberGrowthActionMapper.delete(id);
    }

    @Override
    public long update(MememberGrowthAction mememberGrowthAction) {
        return mememberGrowthActionMapper.update(mememberGrowthAction);
    }

    @Override
    public MememberGrowthAction queryByPrimaryKey(Long id) {
        return mememberGrowthActionMapper.queryByPrimaryKey(id);
    }

    @Override
    public List<MememberGrowthAction> query(MememberGrowthAction mememberGrowthAction) {
        return mememberGrowthActionMapper.query(mememberGrowthAction);
    }

    @Override
    public PageResult<MememberGrowthAction> queryPage(MememberGrowthAction mememberGrowthAction, Page pageQuery) {
        //计算下标
        int startIndex = (pageQuery.getStart() - 1) * pageQuery.getLimit();
        List<MememberGrowthAction> list = mememberGrowthActionMapper.queryPage(startIndex, pageQuery.getLimit(), mememberGrowthAction);
        long count = mememberGrowthActionMapper.queryPageCount(mememberGrowthAction);
        PageResult pageResult = new PageResult();
        pageResult.setRows(list);
        pageResult.setTotal(count);
        return pageResult;
    }

    //根据主表id查询 注册-分享-点赞-晒单-收藏规则信息
    @Override
    public MememberGrowthAction getRrowthRuleById(Long id) {
        RestResult<MemberGrowthRuleResponse> responseRestResult = mememberGrowthRuleService.getDeptInfoById(id);
        MememberGrowthAction mememberGrowthAction = new MememberGrowthAction();
        mememberGrowthAction = mememberGrowthActionMapper.getRrowthRuleById(id);
        mememberGrowthAction.setDeptType(responseRestResult.getData().getDeptType());
        mememberGrowthAction.setDeptName(responseRestResult.getData().getDeptName());
        return mememberGrowthAction;
    }

    @Override
    public MememberGrowthAction getGiveGrowthValById(Long id) {
        MememberGrowthAction mememberGrowthAction = new MememberGrowthAction();
        Long val = mememberGrowthActionMapper.getGiveGrowthValById(id);
        mememberGrowthAction.setGiveGrowthVal(val);
        return mememberGrowthAction;
    }
}